from django.contrib.auth.models import AbstractUser
from django.db import models

class CustomUser(AbstractUser):
    PLATFORM_CHOICES = (
        ('dingtalk', '钉钉'),
        ('uniapp', 'UniApp'),
        ('web', 'Web'),
    )
    
    platform = models.CharField(max_length=10, choices=PLATFORM_CHOICES, default='web', verbose_name="用户平台")
    dingtalk_unionid = models.CharField(max_length=100, blank=True, null=True, unique=True, verbose_name="钉钉UnionID")
    dingtalk_openid = models.CharField(max_length=100, blank=True, null=True, unique=True, verbose_name="钉钉OpenID")
    uniapp_userid = models.CharField(max_length=100, blank=True, null=True, unique=True, verbose_name="UniApp用户ID")
    phone = models.CharField(max_length=15, blank=True, null=True, unique=True, verbose_name="手机号")
    
    class Meta:
        verbose_name = '用户'
        verbose_name_plural = verbose_name
        db_table = 'account_user'
    
    def __str__(self):
        return f"{self.username}({self.get_platform_display()})"